﻿using IntoMes.Global;
using IntoMes.ViewModels;
using Microsoft.Win32;
using MiniExcelLibs;
using System;
using System.Windows;
using System.Windows.Controls;

namespace IntoMes.Views
{
    /// <summary>
    /// ProductionQueryView.xaml 的交互逻辑
    /// </summary>
    public partial class ProductionQueryView : UserControl
    {
        ProductionQueryViewModel vm => Locator.Instance.ProdcutionQuery;
        public ProductionQueryView()
        {
            InitializeComponent();
            //combobox.ItemsSource = null;
            this.DataContext = vm;
        }

        private void Export_Click(object sender, RoutedEventArgs e)
        {
            if (vm.Production.Count == 0)
            {
                MessageBox.Show("请查询数据后，导出");
                return;
            }
            //先获取需要导出的路径
            SaveFileDialog sF = new SaveFileDialog();
            DateTime dt = DateTime.Now;
            string sj = dt.ToString("yyyyMMddHHmmss");
            sF.Filter = "(*.xlsx)|*.xlsx";
            sF.FilterIndex = 0;
            sF.RestoreDirectory = true;
            sF.CreatePrompt = true;
            sF.Title = "导出Excel文件到";
            sF.FileName = sj;
            sF.ShowDialog();
            string fileName = sF.FileName;
            if (!string.IsNullOrEmpty(fileName))
            {
                MiniExcel.SaveAs(fileName, vm.Production);
            }
        }
    }
}
